﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Prism.Games.GalEngine.Scripts.Data.SceneElements;
using Prism.Games.GalEngine.Scripts.Data.ResourceCollection;

namespace Prism.Games.GalEngine.Scripts.Parser
{
    public class EffectSoundParser : ISceneParser
    {
        public EffectSoundParser()
        {
            this.PreSE = new SystemSound() { Id = -1 };
            this.EffectSoundManager = new Audio.AudioManager(Helper.AudioBase.AudioFactory, Helper.AudioBase.SEPlaybackLatency);
        }

        public void ChangeVolume(float volume)
        {
            this.EffectSoundManager.Volume = volume;
        }

        public virtual void Restart()
        {
            this.EffectSoundManager.Reset();
        }

        public SystemSound PreSE { get; set; }

        public Audio.AudioManager EffectSoundManager { get; set; }


        public virtual void PresentObject(FunctionModel.SceneObject element)
        {
            if (element is SystemSound)
            {
                var target = element as SystemSound;

                if (target.IsCached)
                {
                    if (target.Id != this.PreSE.Id)
                    {
                        this.EffectSoundManager.Load(target.CacheStream, target.Id);
                        this.EffectSoundManager.BeginPlay(target.Id);
                    }
                }
            }
        }
    }
}
